<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:sf="http://www.springframework.org/tags/faces"
	template="/WEB-INF/layouts/standard.xhtml">

	<ui:define name="content">
		<h:form id="result">
		<h2>Места в группах</h2>
		<table class="TableTotals">
		<c:set var="rowCnt" value="0"/>
		<c:forEach items="${results}" var="r" varStatus="status">
			<c:set var="rowCnt" value="${rowCnt + 1}"/>
			<c:if test="${status.first}">
				<tr>
					<th rowspan="2">Место</th>
					<th rowspan="2">Участники</th>
					<th rowspan="2">Всего очков</th>
					<c:forEach items="${r.bets}" var="b" step="4">
						<th colspan="4">
							<h:outputText value="${b.groupid}"/>
						</th>
					</c:forEach>
				</tr>
				<tr>
					<c:forEach items="${r.bets}" var="b">
						<th>
							<a href="${b.teamurl}" target="_blank" title="${b.teamname}">
								<!-- <h:outputText value="${b.teamname}"/>
								<br/> -->
								<img src="${request.contextPath}/imageservlet?teamid=${b.teamid}" />
							</a>
						</th>
					</c:forEach>
				</tr>
			</c:if>
			<tr>
				<td align="center" id="cell" class="header"><h:outputText value="${r.participant.placeForGroups}" style="font-weight:bold;color:#{r.participant.placeForGroups==1 ? 'darkred' : 'black'}"/></td>
				<td align="left" id="cell" class="header">
					<c:if test="${empty currentUser.name}">
						<h:outputText value="${r.participant.username}" style="font-weight:bold;color:#{r.participant.placeForGroups==1 ? 'darkred' : 'black'}"/>
					</c:if>						
					<c:if test="${not empty currentUser.name}">
						<h:outputText value="${r.participant.fullname}" style="font-weight:bold;color:#{r.participant.placeForGroups==1 ? 'darkred' : 'black'}"/>
					</c:if>						
				</td>
				<td align="center" id="cell" class="header"><h:outputText value="${r.participant.pointsForGroups}" style="font-weight:bold;color:#{r.participant.placeForGroups==1 ? 'darkred' : 'black'}"/></td>
				<c:forEach items="${r.bets}" var="b">
					<c:set var="vStyle" value="${(( b.teamid + 3 - (b.teamid+3) % 4) / 4) % 2==0?'even':'odd'}"/>
					<c:set var="hStyle" value="${rowCnt % 2==0?'heven':'odd'}"/>
					<c:choose>
					<c:when test="${vStyle == hStyle}">
						<c:set var="tdStyle" value="${vStyle}"/>
					</c:when>
					<c:when test="${vStyle == 'odd'}">
						<c:set var="tdStyle" value="${hStyle}"/>
					</c:when>
					<c:when test="${hStyle == 'odd'}">
						<c:set var="tdStyle" value="${vStyle}"/>
					</c:when>
					<c:otherwise>
						<c:set var="tdStyle" value="${'cross'}"/>
					</c:otherwise>
					</c:choose>
					<td id="cell" class="${tdStyle}">
						<ui:fragment rendered="${isAdmin and rowCnt==1}">
							<sf:commandLink action="edit" processIds="*">
								<f:param name="teamid" value="#{b.teamid}" />
								<h:graphicImage url="/resources/images/EditIcon.gif"/>
							</sf:commandLink>
							<br/>
						</ui:fragment>
						<h:outputText value="${b.groupposition}" style="font-weight:bold;color:#{r.participant.placeForGroups==1 ? 'darkred' : 'black'}"/>
					</td>
				</c:forEach>
			</tr>
		</c:forEach>
		</table>
		</h:form>
	</ui:define>
</ui:composition>